﻿function loadTreeSystem() {
    $('#jstree').empty();
    $.ajax({
        dataType: "json",
        url: "/User/showTreeSys",
        success: function (data) {
            $('#jstree').jstree({ 'core': { 'data': data } });
        }
    });

    $('#jstree a.jstree-anchor').each(function (index) {
        console.log(index);
    });
};
function loadBinaryTree() {
    $('#jstree').empty();
    $.ajax({
        dataType: "json",
        url: "/User/showBinaryTree",
        success: function (data) {
            $('#jstree').jstree({ 'core': { 'data': data } });
        }
    });

    $('#jstree a.jstree-anchor').each(function (index) {
        console.log(index);
    });
};
function changeStatus(_commissionName) {
    $.ajax({
        dataType: "json",
        url: "/CongCu/ChangeSatusCommission/_commissionName=" + _commissionName,
        success: function (data) {

        }
    });
};
function loadTreeTriAn() {
    var tss = $('#_txtTag').val();
    console.log(tss);
    $.ajax({
        dataType: "json",
        cache: false,
        async: true,
        data: { "_node": $('#_txtTag').val() },
        url: "/TriAn/showTreeTriAn",
        success: function (data) {
            $('#jstree').jstree({ 'core': { 'check_callback': true, 'data': data } });
            $('#jstree').jstree(true).settings.core.data = data;
            $('#jstree').jstree('refresh');
        }
    });

    $('#jstree a.jstree-anchor').each(function (index) {
        console.log(index);
    });
}
function loadTreeTriAnDong() {
    var tss = $('#_txtTag').val();
    console.log(tss);
    $.ajax({
        dataType: "json",
        cache: false,
        async: true,
        data: { "_node": $('#_txtTag').val() },
        url: "/TriAnDong/showTreeTriAnDong",
        success: function (data) {
            $('#jstree').jstree({ 'core': { 'check_callback': true, 'data': data } });
            $('#jstree').jstree(true).settings.core.data = data;
            $('#jstree').jstree('refresh');
        }
    });

    $('#jstree a.jstree-anchor').each(function (index) {
        console.log(index);
    });
}
function loadTreeTriAnRap() {
    var tss = $('#_txtTag').val();
    $.ajax({
        dataType: "json",
        cache: false,
        async: true,
        data: { "_node": $('#_txtTag').val() },
        url: "/TriAn/showTreeTriAnRap",
        success: function (data) {
            $('#jstree').jstree({ 'core': { 'check_callback': true, 'data': data } });
            $('#jstree').jstree(true).settings.core.data = data;
            $('#jstree').jstree('refresh');
        }
    });

    $('#jstree a.jstree-anchor').each(function (index) {
        console.log(index);
    });
}
function loadTreeGrateful() {
    $.getJSON("/Home/showData", null, function (data) {
        var members = [];
        for (var prop in data) {
            members.push(data[prop]);
        }
        (function heya(Binary_ID) {
            for (var i = 0; i < members.length; i++) {
                var member = members[i];
                if (member.Binary_ID === Binary_ID) {
                    var parent = Binary_ID ? $("#containerFor" + Binary_ID) : $("#mainContainer"),
                        memberId = member.UserId,
                             metaInfo = "<span><strong>Mã số: </strong>" + member.UserName + "</span>"
                                         + "<span><strong>Họ và tên: </strong>" + member.HOTEN + "</span>"
                                        + "<span><strong>Cấp bậc: </strong>" + member.Level + "</span>"
                                        + "<span><strong>Email: </strong>" + member.EMAIL + "</span>";
                    parent.append("<div class='container2' id='containerFor" + memberId + "'><div class='member'><div class='node node_lv" + member.Level + "' data-name='" + member.HOTEN + "'onclick=\" var data=$(this).data('name'); $('#keyword').val(data); return false; \" ><span class='glyphicon glyphicon-user'></span></div><hr style='width:50%; margin:auto'/><div class='metaInfo'>" +
                        metaInfo
                        + "</div></div></div>");
                    heya(memberId);
                }
            }
        }(null));

        var pretty = function () {
            var self = $(this),
                children = self.children(".container2"),
                width = (49);
            children
                .css("width", width + "%")
                .each(pretty);

        };

        $("#mainContainer").each(pretty);
        $("#mainContainer > .container2").width("100%");
        $(this).val;
    });
    //alert("sdfsd");    
};
function ShowDataPhongCho() {
    $.ajax({
        dataType: "json",
        url: "/ChoNhan/ShowDataPhongCho",
        success: function (data) {
            var listUser = data;
            console.log(listUser);
        }
    });
};